The present invention relates to a portable electronic apparatus which is called an IC card and incorporates an IC (integrated circuit) having, e.g., a nonvolatile data memory and a control element such as a CPU (central processing unit).
Recently, IC cards incorporating IC chips having nonvolatile data memories and control elements such as CPUs have begun to prevail as a new portable data storage medium. The data stored in the data memory incorporated in such an IC card is managed by an internal control element or an external unit.
As a method to access such an IC card, a random access is performed wherein the data memory is divided into a plurality of areas and the respective areas are accessed. In this case, specific data such as a start address of the target area and the number of bytes constituting the area is registered in the IC card. When the target area data is added to input instruction data, the specific data of the target area in the IC card is searched, converted into physical access data, and processed.
However, in a conventional IC card, when data strings are to be written in a target area, they are stored in the order they are input. Response data indicating an input data number error and so on is output only when it is discriminated that no more input data can be stored. In this case, during writing, a data string must be invalidated by some means. For this purpose, conventionally, it is logically invalidated by a flag indicating invalidity of the data string, or this abnormal data string is erased, thereby preventing adverse effects on the subsequent data management.
In this manner, in the conventional IC card, determination whether a data string can be entirely stored in a target area can be known only by a write operation. Therefore, excessive write operations must be performed, the physical service life of the memory is degraded, and protectability of the data in the IC card system is also degraded.